﻿using System;
using System.Data;
using System.Collections.Generic;
using SERP.DAO;
namespace SERP.Controllers{
public class PeopleControllerBase : Controller{
	public PeopleControllerBase()
		: base()
	{
	}
	private static PeopleDAO _Service; 
	public static PeopleDAO Service{
		get{
			if(_Service==null)
				_Service = new PeopleDAO();
			return _Service;
		}
		set{
			_Service = value;
		}
	}
    //Copy data from data row in grid to object
    public PeopleEntity MapDataRowToObject(DataRow row){
		PeopleEntity o = new PeopleEntity();
		 o.PersonCode=Convert.ToString(row["PersonCode"]);
		 o.FullName=Convert.ToString(row["FullName"]);
		 if(!row.IsNull("Gender"))
			o.Gender=ConvertByte(row["Gender"]);
		 if(!row.IsNull("BirthDay"))
			o.BirthDay=ConvertDateTime(row["BirthDay"]);
		 o.Address=Convert.ToString(row["Address"]);
		 o.Phone=Convert.ToString(row["Phone"]);
		 o.Email=Convert.ToString(row["Email"]);
		 if(!row.IsNull("PositionId"))
			o.PositionId=ConvertInt(row["PositionId"]);
		 if(!row.IsNull("StartDate"))
			o.StartDate=ConvertDateTime(row["StartDate"]);
		 o.Note=Convert.ToString(row["Note"]);
		 if(!row.IsNull("UserId"))
			o.UserId=ConvertInt(row["UserId"]);
		 if(!row.IsNull("OrganizationId"))
			o.OrganizationId=(Int32)(row["OrganizationId"]);
		 if(!row.IsNull("PersonTypeId"))
			o.PersonTypeId=(Int32)(row["PersonTypeId"]);
		 if(!row.IsNull("PersonId"))
		    o.PersonId=(Int32)(row["PersonId"]);
		 return o;
    }
	//Copy data from object to data row in grid    
    public void MapObjectToDataRow(PeopleEntity o,DataRow row){
		row["PersonCode"]=o.PersonCode;
		row["FullName"]=o.FullName;
		row["Gender"]=o.Gender;
		row["BirthDay"]=o.BirthDay;
		row["Address"]=o.Address;
		row["Phone"]=o.Phone;
		row["Email"]=o.Email;
		row["PositionId"]=o.PositionId;
		row["StartDate"]=o.StartDate;
		row["Note"]=o.Note;
		row["UserId"]=o.UserId;
		row["OrganizationId"]=o.OrganizationId;
		row["PersonTypeId"]=o.PersonTypeId;
		row["PersonId"]=o.PersonId;
    }
}
}
